import { FilterPlugin } from "./FilterPlugin";
import { TweenLite } from "../TweenLite";
import { EndArrayPlugin } from "./EndArrayPlugin";
//class ColorMatrixFilterPlugin
    
    export  class ColorMatrixFilterPlugin extends FilterPlugin
    {
        constructor()
        {
            
            super();this.propName = "colorMatrixFilter";
            this.overwriteProps = ["colorMatrixFilter"];
            return;
        }

        public /* override */ onInitTween(arg1: Object, arg2, arg3: TweenLite): Boolean
        {
            _target = arg1;
            _type = flash.filters.ColorMatrixFilter;
            var loc1=arg2;
            initFilter({"remove": arg2.remove, "index": arg2.index, "addFilter": arg2.addFilter}, new Object /* flash.filters.ColorMatrixFilter */(ColorMatrixFilterPlugin._idMatrix.slice()), ColorMatrixFilterPlugin._propNames);
            this._matrix = flash.filters.ColorMatrixFilter(_filter).matrix;
            var loc2=[];
            if (!(loc1.matrix == null) && loc1.matrix is Array) 
            {
                loc2 = loc1.matrix;
            }
            else 
            {
                if (loc1.relative != true) 
                {
                    loc2 = ColorMatrixFilterPlugin._idMatrix.slice();
                }
                else 
                {
                    loc2 = this._matrix.slice();
                }
                loc2 = ColorMatrixFilterPlugin.setBrightness(loc2, loc1.brightness);
                loc2 = ColorMatrixFilterPlugin.setContrast(loc2, loc1.contrast);
                loc2 = ColorMatrixFilterPlugin.setHue(loc2, loc1.hue);
                loc2 = ColorMatrixFilterPlugin.setSaturation(loc2, loc1.saturation);
                loc2 = ColorMatrixFilterPlugin.setThreshold(loc2, loc1.threshold);
                if (!isNaN(loc1.colorize)) 
                {
                    loc2 = ColorMatrixFilterPlugin.colorize(loc2, loc1.colorize, loc1.amount);
                }
            }
            this._matrixTween = new EndArrayPlugin();
            this._matrixTween.init(this._matrix, loc2);
            return true;
        }

        public /* override */ set changeFactor(arg1: number)
        {
            this._matrixTween.changeFactor = arg1;
            flash.filters.ColorMatrixFilter(_filter).matrix = this._matrix;
            super.changeFactor = arg1;
            return;
        }

        public static colorize(arg1: Array<any>, arg2: number, arg3: number=1): Array<any>
        {
            if (isNaN(arg2)) 
            {
                return arg1;
            }
            if (isNaN(arg3)) 
            {
                arg3 = 1;
            }
            var loc1=(arg2 >> 16 & 255) / 255;
            var loc2=(arg2 >> 8 & 255) / 255;
            var loc3=(arg2 & 255) / 255;
            var loc4;
            var loc5=[(loc4 = 1 - arg3) + arg3 * loc1 * ColorMatrixFilterPlugin._lumR, arg3 * loc1 * ColorMatrixFilterPlugin._lumG, arg3 * loc1 * ColorMatrixFilterPlugin._lumB, 0, 0, arg3 * loc2 * ColorMatrixFilterPlugin._lumR, loc4 + arg3 * loc2 * ColorMatrixFilterPlugin._lumG, arg3 * loc2 * ColorMatrixFilterPlugin._lumB, 0, 0, arg3 * loc3 * ColorMatrixFilterPlugin._lumR, arg3 * loc3 * ColorMatrixFilterPlugin._lumG, loc4 + arg3 * loc3 * ColorMatrixFilterPlugin._lumB, 0, 0, 0, 0, 0, 1, 0];
            return ColorMatrixFilterPlugin.applyMatrix(loc5, arg1);
        }

        public static setThreshold(arg1: Array<any>, arg2: number): Array<any>
        {
            if (isNaN(arg2)) 
            {
                return arg1;
            }
            var loc1=[ColorMatrixFilterPlugin._lumR * 256, ColorMatrixFilterPlugin._lumG * 256, ColorMatrixFilterPlugin._lumB * 256, 0, -256 * arg2, ColorMatrixFilterPlugin._lumR * 256, ColorMatrixFilterPlugin._lumG * 256, ColorMatrixFilterPlugin._lumB * 256, 0, -256 * arg2, ColorMatrixFilterPlugin._lumR * 256, ColorMatrixFilterPlugin._lumG * 256, ColorMatrixFilterPlugin._lumB * 256, 0, -256 * arg2, 0, 0, 0, 1, 0];
            return ColorMatrixFilterPlugin.applyMatrix(loc1, arg1);
        }

        public static setHue(arg1: Array<any>, arg2: number): Array<any>
        {
            if (isNaN(arg2)) 
            {
                return arg1;
            }
            arg2 = arg2 * Math.PI / 180;
            var loc1=Math.cos(arg2);
            var loc2=Math.sin(arg2);
            var loc3=[ColorMatrixFilterPlugin._lumR + loc1 * (1 - ColorMatrixFilterPlugin._lumR) + loc2 * (-ColorMatrixFilterPlugin._lumR), ColorMatrixFilterPlugin._lumG + loc1 * (-ColorMatrixFilterPlugin._lumG) + loc2 * (-ColorMatrixFilterPlugin._lumG), ColorMatrixFilterPlugin._lumB + loc1 * (-ColorMatrixFilterPlugin._lumB) + loc2 * (1 - ColorMatrixFilterPlugin._lumB), 0, 0, ColorMatrixFilterPlugin._lumR + loc1 * (-ColorMatrixFilterPlugin._lumR) + loc2 * 0.143, ColorMatrixFilterPlugin._lumG + loc1 * (1 - ColorMatrixFilterPlugin._lumG) + loc2 * 0.14, ColorMatrixFilterPlugin._lumB + loc1 * (-ColorMatrixFilterPlugin._lumB) + loc2 * -0.283, 0, 0, ColorMatrixFilterPlugin._lumR + loc1 * (-ColorMatrixFilterPlugin._lumR) + loc2 * (-(1 - ColorMatrixFilterPlugin._lumR)), ColorMatrixFilterPlugin._lumG + loc1 * (-ColorMatrixFilterPlugin._lumG) + loc2 * ColorMatrixFilterPlugin._lumG, ColorMatrixFilterPlugin._lumB + loc1 * (1 - ColorMatrixFilterPlugin._lumB) + loc2 * ColorMatrixFilterPlugin._lumB, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1];
            return ColorMatrixFilterPlugin.applyMatrix(loc3, arg1);
        }

        public static setBrightness(arg1: Array<any>, arg2: number): Array<any>
        {
            if (isNaN(arg2)) 
            {
                return arg1;
            }
            arg2 = arg2 * 100 - 100;
            return ColorMatrixFilterPlugin.applyMatrix([1, 0, 0, 0, arg2, 0, 1, 0, 0, arg2, 0, 0, 1, 0, arg2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], arg1);
        }

        public static setSaturation(arg1: Array<any>, arg2: number): Array<any>
        {
            if (isNaN(arg2)) 
            {
                return arg1;
            }
            var loc1=1 - arg2;
            var loc2=loc1 * ColorMatrixFilterPlugin._lumR;
            var loc3=loc1 * ColorMatrixFilterPlugin._lumG;
            var loc4=loc1 * ColorMatrixFilterPlugin._lumB;
            var loc5=[loc2 + arg2, loc3, loc4, 0, 0, loc2, loc3 + arg2, loc4, 0, 0, loc2, loc3, loc4 + arg2, 0, 0, 0, 0, 0, 1, 0];
            return ColorMatrixFilterPlugin.applyMatrix(loc5, arg1);
        }

        public static setContrast(arg1: Array<any>, arg2: number): Array<any>
        {
            if (isNaN(arg2)) 
            {
                return arg1;
            }
            arg2 = arg2 + 0.01;
            var loc1=[arg2, 0, 0, 0, 128 * (1 - arg2), 0, arg2, 0, 0, 128 * (1 - arg2), 0, 0, arg2, 0, 128 * (1 - arg2), 0, 0, 0, 1, 0];
            return ColorMatrixFilterPlugin.applyMatrix(loc1, arg1);
        }

        public static applyMatrix(arg1: Array<any>, arg2: Array<any>): Array<any>
        {
            var loc4=0;
            var loc5=0;
            if (typeof !(arg1 === "array") || !(arg2 is Array)) 
            {
                return arg2;
            }
            var loc1=[];
            var loc2=0;
            var loc3=0;
            loc4 = 0;
            while (loc4 < 4) 
            {
                loc5 = 0;
                while (loc5 < 5) 
                {
                    if (loc5 != 4) 
                    {
                        loc3 = 0;
                    }
                    else 
                    {
                        loc3 = arg1[loc2 + 4];
                    }
                    loc1[loc2 + loc5] = arg1[loc2] * arg2[loc5] + arg1[loc2 + 1] * arg2[loc5 + 5] + arg1[loc2 + 2] * arg2[loc5 + 10] + arg1[loc2 + 3] * arg2[loc5 + 15] + loc3;
                    ++loc5;
                }
                loc2 = loc2 + 5;
                ++loc4;
            }
            return loc1;
        }

        public static /* const */API: number=1;

        protected /* var */_matrix: Array<any>;

        protected /* var */_matrixTween: EndArrayPlugin;

        private static /* var */_propNames: Array<any>;

        protected static /* var */_idMatrix: Array<any>;

        protected static /* var */_lumR: number=0.212671;

        protected static /* var */_lumG: number=0.71516;

        protected static /* var */_lumB: number=0.072169;
    }

            ColorMatrixFilterPlugin._propNames = [];
            ColorMatrixFilterPlugin._idMatrix = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
            ColorMatrixFilterPlugin._lumR = 0.212671;
            ColorMatrixFilterPlugin._lumG = 0.71516;
            ColorMatrixFilterPlugin._lumB = 0.072169;
        